var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: '',
    isShow: false,
    userId: '',
    employeeInfo: '',
    isBoss: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userId = options.userId;
    var that = this;
    var type = options.type;
    that.setData({
      type: type,
      userId: userId
    })
    this.getEmployeeInfo();
  },
  /**
   * 得到员工信息
   */
  getEmployeeInfo: function () {
    var that = this;
    var storeId = app.globalData.storeId;
    var userId = that.data.userId;
    var data = {
      storeUserId: userId
    }
    req.storeRequest("请稍等", "POST",url.store['getStoreUserInfo'], storeId, data, function back(res) {
      console.log(res);
      that.setData({
        employeeInfo: res.data
      })
      if (that.data.type != 0) {
        that.setData({
          isBoss: false
        })
      } else {
        if (that.data.employeeInfo['type'] == 2) {
          that.setData({
            isShow: true
          })
        }
      }
    })
  },
  /**
  * 设置店长/员工
  */
  changeCharacter: function (event) {
    var that = this;
    var type = event.currentTarget.dataset.num;
    var userId = that.data.employeeInfo['userId'];
    var data = {
      type: type,
      storeUserId: userId
    };
    var storeId = app.globalData.storeId;
    wx.showModal({
      title: '提示',
      content: '您确定修改员工属性',
      success: function (res) {
        if (res.confirm) {
          req.storeRequest("请稍等", "POST", url.store['setStoreIdentity'], storeId, data, function back(res) {
            var employeeInfo = that.data.employeeInfo;
            if (parseInt(type) == 2) {
              employeeInfo['type'] = 2
              that.setData({
                isShow: true
              })
            } else {
              employeeInfo['type'] = 1
              that.setData({
                isShow: false
              })
            }
            that.setData({
              employeeInfo: employeeInfo
            })
          })
        }
      }
    })
  }
})